package com.kgcx.order.rabbitmq;

import com.alibaba.fastjson.JSONObject;
import com.kgcx.common.rabbitmq.bean.Message;
import com.kgcx.common.rabbitmq.consts.ExchangeConst;
import com.kgcx.common.rabbitmq.consts.RoutingKeyConst;
import com.kgcx.order.domain.PayRecordDomain;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 支付完成队列
 * @author qinze
 *
 */
@Slf4j
@Component
public class PayProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    private static final String TYPE = "operatePay";

    public void addPayProducer(PayRecordDomain payRecordDomain) {
        log.info(String.format("支付订单完成，订单号[%s]。", payRecordDomain.getOrderNo()));
        Message msg = Message.buildMessage(TYPE, Message.FLAG_ADD, payRecordDomain);
        rabbitTemplate.convertAndSend(ExchangeConst.OPC, RoutingKeyConst.OPC_COMMON,JSONObject.toJSONString(msg));
        log.info(String.format("msgId[%s]。", msg.getId()));
    }

}
